package cn.getech.data.development.entity.permission;

import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel
public class SysRoleDataPermission implements Serializable {
    private Integer id;

    /**
    * 角色id
    */
    @ApiModelProperty("角色id")
    private Long roleId;

    /**
    * 数据id
    */
    @ApiModelProperty("数据id")
    private Integer dataId;

    /**
    * 1 数据源 ，2 数据仓库表，3数据仓库表字段，4数据服务,5元数据
    */
    @ApiModelProperty("1 数据源 ，2 数据仓库表，3数据仓库表字段，4数据服务,5元数据管理")
    private Integer dataType;

    /**
    * 查询权限 1 拥有,0 未拥有
    */
    @ApiModelProperty("查询权限 1 拥有,0 未拥有")
    private Integer query;

    /**
    * 修改权限 1 拥有,0 未拥有
    */
    @ApiModelProperty("修改权限 1 拥有,0 未拥有")
    private Integer update;

    @ApiModelProperty("数据写入权限 1 拥有,0 未拥有")
    private Integer write;

    /**
    * 删除权限 1 拥有,0 未拥有
    */
    @ApiModelProperty("删除权限 1 拥有,0 未拥有")
    private Integer delete;

    /**
    * 创建权限 1 拥有,0 未拥有
    */
    @ApiModelProperty("创建权限 1 拥有,0 未拥有")
    private Integer create;

    /**
    * 授权权限 1 拥有,0 未拥有
    */
    @ApiModelProperty("授权权限 1 拥有,0 未拥有")
    private Integer assign;

    /**
    * 导出权限 1 拥有,0 未拥有
    */
    @ApiModelProperty("导出权限 1 拥有,0 未拥有")
    private Integer export;

    /**
    * 加密权限 1 拥有,0 未拥有
    */
    @ApiModelProperty("加密权限 1 拥有,0 未拥有")
    private Integer decrypt;

    public void defaultValue(Long roleId, Integer dataId, Integer dataType) {
        this.roleId = roleId;
        this.dataId = dataId;
        this.dataType = dataType;
        this.query = 0;
        this.update = 0;
        this.delete = 0;
        this.create = 0;
        this.assign = 0;
        this.export = 0;
        this.decrypt = 0;
        this.write = 0;
    }
    public SysRoleDataPermission toPermission(SysRoleDataPermission sysRoleDataPermission) {
        SysRoleDataPermission permission = new SysRoleDataPermission();
        permission.setQuery(sysRoleDataPermission.getQuery());
        permission.setCreate(sysRoleDataPermission.getCreate());
        permission.setUpdate(sysRoleDataPermission.getUpdate());
        permission.setDelete(sysRoleDataPermission.getDelete());
        permission.setAssign(sysRoleDataPermission.getAssign());
        permission.setDecrypt(sysRoleDataPermission.getDecrypt());
        permission.setExport(sysRoleDataPermission.getExport());
        permission.setDataId(sysRoleDataPermission.getDataId());
        permission.setRoleId(sysRoleDataPermission.getRoleId());
        permission.setDataType(sysRoleDataPermission.getDataType());
        permission.setId(sysRoleDataPermission.getId());
        permission.setWrite(sysRoleDataPermission.getWrite());
        return permission;
    }
    /**
     * 前端需要一天临时唯一的id
     */
    @ApiModelProperty("前端需要一天临时唯一的id")
    @TableField(exist = false)
    private String uniqueId;

    public String getUniqueId() {
        return this.getDataId()+"_"+this.getDataType();
    }


    public void yesValue(Long roleId, Integer dataId, Integer dataType) {
        this.roleId = roleId;
        this.dataId = dataId;
        this.dataType = dataType;
        this.query = 1;
        this.update = 1;
        this.delete = 1;
        this.create = 1;
        this.assign = 1;
        this.export = 1;
        this.decrypt = 1;
        this.write = 1;
    }
}